package com.tjian.fafa.user.util.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author haoren
 * @version _20141230_152217
 */
public class DateUtilOfDemohi
{

    /**
     * 判断当前日期是星期几
     *
     * @param pTime 要判断的时间
     * @return dayForWeek 判断结果
     */
    public static int dayForWeek(String pTime) throws Exception
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        c.setTime(format.parse(pTime));
        int dayForWeek = 0;
        if (c.get(Calendar.DAY_OF_WEEK) == 1)
        {
            dayForWeek = 7;
        }
        else
        {
            dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
        }
        return dayForWeek;
    }

    public static int acquireWeek()
    {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date(System.currentTimeMillis()));
        int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
        if (dayOfWeek == 1)
        {
            //System.out.println("星期日");
            dayOfWeek = 7;
            return dayOfWeek;
        }
        if (dayOfWeek == 2)
        {
            //System.out.println("星期一");
            dayOfWeek = 1;
            return dayOfWeek;
        }
        if (dayOfWeek == 3)
        {
            //System.out.println("星期二");
            dayOfWeek = 2;
            return dayOfWeek;
        }
        if (dayOfWeek == 4)
        {
            //System.out.println("星期三");
            dayOfWeek = 3;
            return dayOfWeek;
        }
        if (dayOfWeek == 5)
        {
            //System.out.println("星期四");
            dayOfWeek = 4;
            return dayOfWeek;
        }
        if (dayOfWeek == 6)
        {
            //System.out.println("星期五");
            dayOfWeek = 5;
            return dayOfWeek;
        }
        if (dayOfWeek == 7)
        {
            //System.out.println("星期六");
            dayOfWeek = 6;
            return dayOfWeek;
        }
        return dayOfWeek;
    }

    /**
     * 获取当天日期
     *
     * @return
     */
    public static String getCurrentDate()
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(new Date());
    }

}
